<template>
	<view>
		<view class="wrap">
			<view class="order-header">
				<view class="u-tabs-box">
					<u-tabs-swiper activeColor="#10beca" ref="tabs"
						:list="list" :current="current" @change="change" :is-scroll="false" swiperWidth="750">
					</u-tabs-swiper>
				</view>
				<view class="u-p-30 bg-white">
					<u-search v-model="key" :show-action="false" clearabled @change="searchKeyword"></u-search>
				</view>
			</view>
			<swiper class="swiper-box" :current="swiperCurrent" @transition="transition"
				@animationfinish="animationfinish">
				<swiper-item class="swiper-item" v-for="(list,i) in orderList" :key="i">
					<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="reachBottom">
						<u-cell-group class="u-m-b-20" v-if="orderList[i].length > 0">
							<u-cell-item :title="res.number" :title-style="{color: '#303133'}" v-for="(res, index) in orderList[i]" :key="res.id" :use-label-slot="true" @click="details(res)">
								<view slot="label">
									<!-- <view class="pack">
										<view class="item">
											<view class="name u-font-32 u-m-b-10">{{res.storenames}}</view>
											<view class="text u-line-1">--</view>
										</view>
										<view class="u-p-l-20 u-p-r-20 u-text-center">
											<text class="iconfont icon-daoda u-font-60 u-tips-color"></text>
											<view><text>{{res.licenseplate}}</text></view>
										</view>
										<view class="item u-text-right">
											<view class="name u-font-32 u-m-b-10">{{res.packstation.name}}</view>
											<view class="text u-line-1">--</view>
										</view>
									</view> -->
									<view><text>移库到：{{res.store.name}}</text></view>
									<view><text>建单时间：{{res.createddatetime}}</text></view>
									<view><text>备注：{{res.remarks?res.remarks:'--'}}</text></view>
									<!-- <view class="u-flex time">
										<view class="u-flex-1">
											<u-icon name="clock" :size="24" color="rgb(94,94,94)"></u-icon>
											<text class="u-tips-color">{{$u.timeFormat(res.demandtime, 'yyyy-mm-dd hh:MM:ss')}}</text>
										</view>
										<view>
											<u-icon name="car" :size="24" color="rgb(94,94,94)"></u-icon>
											<text class="u-tips-color">总重量{{res.weight}}KG</text>
										</view>
									</view> -->
								</view>
								<view slot="right-icon">
									<u-tag :text="res.state" mode="plain" size="mini" />
								</view>
							</u-cell-item>
						</u-cell-group>

						<u-empty v-else text="您还没有相关的订单" mode="list"></u-empty>
					</scroll-view>
				</swiper-item>
			</swiper>
		</view>
		<!-- <view class="radiusBtn" @tap="create"><u-icon name="plus" size="60" color="#fff"></u-icon></view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [
					// {
					// 	name: '待移库'
					// },
					{
						value: '',
						name: '全部'
					},
					{
						value: 1,
						name: '已完结'
					},
					{
						value: 2,
						name: '已取消'
					}
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['loadmore', 'loadmore'],
				PageIndex: 1,
				PageSize: 20,
				noMore: false,
				key: '',
				orderList: [[],[],[]]
			}
		},
		onShow() {
			this.orderList[this.swiperCurrent] = []
			this.PageIndex = 1
			this.getOrderList(this.swiperCurrent);
		},
		onPullDownRefresh() {
			this.orderList[this.swiperCurrent] = []
			this.PageIndex = 1
			this.getOrderList(this.swiperCurrent).then(() => {
				uni.stopPullDownRefresh(); //停止当前页面下拉刷新
			})
		},
		methods: {
			// 查看详情
			details(item){
				uni.navigateTo({
					url: '/pages/brother/transferOrder/details/details?id='+item.id
				})
			},
			// 新建入库单
			// create(){
			// 	uni.navigateTo({
			// 		url: '/pages/brother/incomOrder/create/create'
			// 	})
			// },
			reachBottom() {
				// 此tab为空数据
				this.PageIndex += 1
				if (!this.noMore) {
					this.getOrderList(this.swiperCurrent).then((row) => {
						if (row.length == 0) {
							this.noMore = true
						}
					})
				}
			},
			// 页面数据
			getOrderList(idx) {
				this.loadStatus.splice(this.swiperCurrent, 1, "loading")
			
				return this.$u.post('Brother/TransferOrder/List', {
					"PageIndex": this.PageIndex,
					"PageSize": this.PageSize,
					"key": this.key,
					"state": this.list[this.swiperCurrent].value
					// "Order": [{column:'Sort', isdesc: true}, {column:'Id', isdesc: true}],
					// "assignmentState": 0,
					// "state": 0,
					// "manageState": 0
				}).then((res) => {
					if (res.rows.length > 0) {
						res.rows.forEach((item) => {
							this.orderList[idx].push(item)
						})
						if (res.rows.length < this.PageSize) {
							this.loadStatus.splice(this.swiperCurrent, 1, "nomore")
						} else {
							this.loadStatus.splice(this.swiperCurrent, 1, "loadmore")
						}
					} else {
						this.loadStatus.splice(this.swiperCurrent, 1, "nomore")
					}
					this.$forceUpdate()
					return res.rows
				})
			},
			// tab栏切换
			change(index) {
				this.PageIndex = 1;
				this.swiperCurrent = index;
				this.orderList[index] = [];
				this.noMore = false;
				this.getOrderList(index);
			},
			transition({
				detail: {
					dx
				}
			}) {
				this.$refs.tabs.setDx(dx);
			},
			animationfinish({
				detail: {
					current
				}
			}) {
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
			
				if (current != this.current) { //滑动切换到其他分类时
					this.current = current;
					this.orderList[this.current] = []
					this.loadStatus.splice(this.current, 1, "loadmore")
					this.getOrderList(this.current)
				} else {
					this.current = current;
				}
			},
			searchKeyword(val){
				this.key = val
				this.PageIndex = 1;
				this.orderList[this.swiperCurrent] = [];
				this.getOrderList(this.swiperCurrent);
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page-box {
		// background-color: #f2f2f2;
	}
	
	.radiusBtn{
		position: fixed;
		right: 60rpx;
		bottom: 60rpx;
		width: 100rpx;
		height: 100rpx;
		background-color: $u-color-main;
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.order-header {
		box-sizing: content-box;
		padding-top: 1px;
	
		.header {
			height: 44px;
			padding: 0 20rpx;
			display: flex;
			align-items: center;
		}
	}
	
	.wrap {
		display: flex;
		flex-direction: column;
		height: calc(100vh - var(--window-top));
		width: 100%;
	}
	
	.swiper-box {
		flex: 1;
	}
	
	.swiper-item {
		height: 100%;
		.pack{
			display: flex;
			align-items: center;
			width: 640rpx;
			margin: 20rpx 0;
			.item{
				width: 200rpx;
				flex: 1;
				
				.name{
					color: $u-color-dark;
				}
				.text{
				}
			}
			// .icon{
			// 	font-size: 60rpx;
			// 	padding: 0 80rpx;
			// 	transform: rotate(90deg);
			// 	color: var(--gray);
			// }
		}
		.time{
			color: $u-color-dark;
		}
	}
</style>
